package com.puman.beautyfarmcounselor.ui.schedule.adpter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.puman.beautyfarmcounselor.MainActivity;
import com.puman.beautyfarmcounselor.R;
import com.puman.beautyfarmcounselor.ui.schedule.modle.DayWeekInfo;
import com.puman.beautyfarmcounselor.ui.schedule.modle.Schedule;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Curry on 2015/6/18.
 */
public class DayWeekAdapter extends BaseAdapter {
    private LayoutInflater layoutInflater;
//    private List<DayWeekInfo> dateTime = new ArrayList<DayWeekInfo>();//datetime
    private  Context context;
    Schedule schedule;

    public final class viewHolder {
        public TextView workTypeInfo;
        public TextView dayOfweekIno;
        public RelativeLayout itemLayout;
    }

    public DayWeekAdapter(Context context, Schedule schedule) {
        layoutInflater = LayoutInflater.from(context);
        this.schedule = schedule;
        this.context = context;
    }

    @Override
    public int getCount() {
        return schedule.getData().size();
    }

    @Override
    public Object getItem(int position) {
        return schedule.getData().get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final viewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new viewHolder();
            convertView = layoutInflater.inflate(R.layout.day_week_item, null);
            viewHolder.itemLayout = (RelativeLayout) convertView.findViewById(R.id.dayweek_item_bg_layout);
            viewHolder.dayOfweekIno = (TextView) convertView.findViewById(R.id.dayweek_item_info);
            viewHolder.workTypeInfo = (TextView) convertView.findViewById(R.id.dayweek_item_work_type);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (viewHolder) convertView.getTag();
        }
        viewHolder.dayOfweekIno.setText(schedule.getData().get(position).getDateNo());
//        Log.i("curry", position+":getDate:"+schedule.getData().get(position).getDate()+"*getSchedule_name:"+schedule.getData().get(position).getSchedule_name());
        if (schedule.getData().get(position).getSchedule_name().equals("中班")){
            if (schedule.getData().get(position).isSelect()){
                viewHolder.dayOfweekIno.setTextColor(context.getResources().getColor(R.color.white));
                viewHolder.workTypeInfo.setTextColor(context.getResources().getColor(R.color.white));
                viewHolder.itemLayout.setBackgroundDrawable(MainActivity.getInstace().getResources().getDrawable(R.drawable.work_type_moning));
            }else{
                viewHolder.dayOfweekIno.setTextColor(context.getResources().getColor(R.color.schedule_dayofweek));
                viewHolder.workTypeInfo.setTextColor(context.getResources().getColor(R.color.schedule_dayofweek));
                viewHolder.itemLayout.setBackgroundColor(MainActivity.getInstace().getResources().getColor(R.color.white));
            }
            viewHolder.workTypeInfo.setText("早");
        }else if (schedule.getData().get(position).getSchedule_name().equals("晚班")) {
            if (schedule.getData().get(position).isSelect()){
                viewHolder.dayOfweekIno.setTextColor(context.getResources().getColor(R.color.white));
                viewHolder.workTypeInfo.setTextColor(context.getResources().getColor(R.color.white));
                viewHolder.itemLayout.setBackgroundDrawable(MainActivity.getInstace().getResources().getDrawable(R.drawable.work_type_night));
            }else{
                viewHolder.dayOfweekIno.setTextColor(context.getResources().getColor(R.color.schedule_dayofweek));
                viewHolder.workTypeInfo.setTextColor(context.getResources().getColor(R.color.schedule_dayofweek));
                viewHolder.itemLayout.setBackgroundColor(MainActivity.getInstace().getResources().getColor(R.color.white));
            }
            viewHolder.workTypeInfo.setText("晚");
        }else if (schedule.getData().get(position).getSchedule_name().equals("")) {
            if (schedule.getData().get(position).isSelect()){
                viewHolder.dayOfweekIno.setTextColor(context.getResources().getColor(R.color.white));
                viewHolder.workTypeInfo.setTextColor(context.getResources().getColor(R.color.white));
                viewHolder.itemLayout.setBackgroundDrawable(MainActivity.getInstace().getResources().getDrawable(R.drawable.work_type_rest));
            }else{
                viewHolder.dayOfweekIno.setTextColor(context.getResources().getColor(R.color.schedule_dayofweek));
                viewHolder.workTypeInfo.setTextColor(context.getResources().getColor(R.color.schedule_dayofweek));
                viewHolder.itemLayout.setBackgroundColor(MainActivity.getInstace().getResources().getColor(R.color.white));
            }
            viewHolder.workTypeInfo.setText("休");
        }else{
            viewHolder.itemLayout.setBackgroundColor(MainActivity.getInstace().getResources().getColor(R.color.white));
        }

        return convertView;
    }

}
